package com.wyd.studentboot.controller;

import com.wyd.studentboot.bean.UserBean;
import com.wyd.studentboot.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
public class LoginController {

    @Autowired
    UserService userService;

    @RequestMapping("/login")
    public String show(){
        return "login";
    }

    @RequestMapping(value = "/loginIn",method = RequestMethod.POST)
    public String login(String username, String password, HttpServletRequest request){
        UserBean userBean = userService.loginIn(username,password);
        if(userBean!=null){
            HttpSession session=request.getSession();
            session.setAttribute("loginname",username);
            session.setAttribute("user",userBean);
            return "layuibank";
        }else {
            return "error";
        }
    }
}
